@include('Home.head')
<link rel="stylesheet" href="{{ URL::asset('css/home/layui.css') }}">
<body>
<div class="container" id="app">
    <header data-am-widget="header" class="am-header am-header-default my-header">
        <div class="am-header-left am-header-nav">
            <a  onclick="javascript:history.back(-1);" class="">
                <i class="am-header-icon am-icon-chevron-left"></i>
            </a>
        </div>
        <h1 class="am-header-title">
            <a href="#title-link" class="">@{{ title }}</a>
        </h1>
        <div class="am-header-right am-header-nav">
            <a href="/home/member/index" class="">
                <i class="am-header-icon  am-icon-home"></i>
            </a>
        </div>
    </header>
     <div class="my-nav-bar">
        <ol class="am-breadcrumb">
          <li><a href="/home/stores/index">门店中心</a></li>
          <li><a href="">收益</a></li>
        </ol>
    </div>
    {{--<div class="flow-default am-cf cart-panel" id="LAY_demo1" v-on:click='detail()'>--}}

    <div class="flow-default am-cf cart-panel" id="LAY_demo1">

    	{{--<div class="withdrawals-panel" v-for="val in order">--}}

            {{--<div class="uchome-info-uimg" style="width: 20%" >--}}
                {{--<img src="/img/home/user/img1.jpg" style="width: 50px;height: 50px;margin: 14px"/>--}}
            {{--</div>--}}
            {{--<div class="groupby-info-panle" style="width: 28%">--}}
                {{--<h2><a href="#">@{{ val.money }}</a></h2>--}}
            {{--</div>--}}
            {{--<div class="groupby-info-panle" style="width: 52%">--}}
                {{--<h3><a href="#">@{{ val.explain }}</a></h3>--}}
                {{--<p>订单号：@{{ val.ordersn }}</p>--}}
                {{--<p>交易时间：@{{ val.time }}</p>--}}
                {{--<p v-show="val.remark">备注：@{{ val.remark }}</p>--}}
            {{--</div>--}}
        {{--</div>--}}
    </div>
    @include('Home.foot')
</div>
</body>
<script src="{{ URL::asset('js/admin/layui/layui.js') }}"></script>
<script>
    layui.use('flow', function(){
        var flow = layui.flow;
        flow.load({
            elem: '#LAY_demo1' //流加载容器
            // ,scrollElem: '#LAY_demo1' //滚动条所在元素，一般不用填，此处只是演示需要。
            ,done: function(page, next){ //执行下一页的回调
                //模拟数据插入
                setTimeout(function(){
                    var lis = [];
                    var order = app.order;
                    app.nextData();
                    for(var i = 0; i < app.order.length; i++){
                        lis.push(
                            "<div class='withdrawals-panel'>"+
                            "<div class='uchome-info-uimg'   style='width: 20%' >"+
                            " <img src='/img/home/user/5.png' style='width: 50px;height: 50px;margin: 14px'/>"+
                            "</div>"+
                            "<div class='groupby-info-panle' style='width: 28%'>"+
                            "<h2><a >"+order[i].currency+"</a></h2>"+

                            "</div>"+
                            "<div class='groupby-info-panle' style='width: 52%'>"+
                             "<p><h2>收益说明</h2></p>"+
                            "<p>"+order[i].source_store+"</p>"+
                            "<p>消费订单号："+order[i].ordersn+"</p>"+
                            "<p>消费类型："+order[i].consum_type+"</p>"+
                            "<p>门店收益类型："+order[i].profit_type+"</p>"+
                            "<p>收益时间："+order[i].addtime+"</p>"+
                            "</div>"
                            +"</div>"
                        )
                    }
                    //执行下一页渲染，第二参数为：满足“加载更多”的条件，即后面仍有分页
                    //pages为Ajax返回的总页数，只有当前页小于总页数的情况下，才会继续出现加载更多
                        next(lis.join('') , page <= app.pages.last_page); //假设总页数为 10
                }, 500);
            }
        });
    });

    var app = new Vue({
        el: "#app",
        data: {
            title: '门店收益记录',
            order:{
            },
            recordNum:'',
            pages:{
                current_page:0,
            },
            id:''
        },
        methods: {

            //初始化
            initialize: function () {
                var rico = this;
                var id = this.obtain('id');
                $.post("/home/member/record", {'_token': '{{csrf_token()}}',class:'stores_profit',id:id }, function (res) {
                    if (res.code) {
                        //console.log(res.data);
                        //console.log(res.recordNum);
                        app.id = id;
                        app.pages = res.data;
                        app.order = res.data.data;
                        app.recordNum = res.recordNum;
                        for(var i=0;app.order.length>i;i++){
                            app.order[i].addtime = rico.formatDateTime(app.order[i].addtime);
                        }
                    } else {
                        layer.msg(res.data);
                    }
                });
            },
            formatDateTime:function (timeStamp) {
                var date = new Date();
                date.setTime(timeStamp * 1000);
                var y = date.getFullYear();
                var m = date.getMonth() + 1;
                m = m < 10 ? ('0' + m) : m;
                var d = date.getDate();
                d = d < 10 ? ('0' + d) : d;
                var h = date.getHours();
                h = h < 10 ? ('0' + h) : h;
                var minute = date.getMinutes();
                var second = date.getSeconds();
                minute = minute < 10 ? ('0' + minute) : minute;
                second = second < 10 ? ('0' + second) : second;
                return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second;
            },

            //下一页
            nextData:function(){
                //page:app.pages.per_page+1
                var rico = this
                $.get("/home/member/record", {'_token': '{{csrf_token()}}',class:'stores_profit',id:app.id, page:app.pages.current_page+1
                }, function (res) {
                    if (res.code) {
                        app.pages = res.data
                        app.order = res.data.data
                        for(var i=0;app.order.length>i;i++){
                            app.order[i].addtime = rico.formatDateTime(app.order[i].addtime)

                        }
                    } else {
                        layer.msg(res.data);
                    }
                });
            },
            //详细记录
            detail:function(e){
               // location.href = "/home/member/recordDetail";
            },
            //获取url id
            obtain:function (val) {
                var query = window.location.search.substring(1);
                var vars = query.split("&");
                for (var i=0;i<vars.length;i++) {
                    var pair = vars[i].split("=");
                    if(pair[0] == val){
                        return pair[1];
                    }
                }
            }
        },

        //自动执行
        mounted: function () {
            this.initialize();
        },
    })
</script>
</html>
